package com.zhida.smartcontrol.dialog.dimmerdialog;

import com.zhida.smartcontrol.common.Api;
import com.zhida.smartcontrol.common.Const;
import com.zhida.smartcontrol.common.bean.LampSwitchBean;
import com.zhida.smartcontrol.knet.KalleCallBack;
import com.zhida.smartcontrol.mvp.BasePresenterImpl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class DimmerDialogPresenter extends BasePresenterImpl<DimmerDialogContract.View> implements DimmerDialogContract.Presenter {

    @Override
    public void plcBrightness(List<LampSwitchBean> codeList, String type) {
        List<String> list = new ArrayList<>();
        for (LampSwitchBean lampBean : codeList) {
            list.add(lampBean.getId());
        }
        Map<String, Object> params = new HashMap<>();
        params.put("idList", list);
        params.put("type", type); //1：100%         2：75%       3：50%       4：25%       0：0%
        mKalleCenter.postJson(Api.ADJUST_PLC_BRIGHTNESSES, params, true, new KalleCallBack() {
            @Override
            public void onSuccess(String result, String msg) {
                mView.showMsg(msg);
                mView.onSuccess();
            }

            @Override
            public void onFailed(String msg) {
                if (null != mView)
                    mView.showMsg(msg);
            }
        });
    }

    @Override
    public void nbBrightness(int switchType, List<LampSwitchBean> codeList, String value) {
        List<String> list = new ArrayList<>();

        for (LampSwitchBean lampBean : codeList) {
            list.add(lampBean.getCode());
        }
        String type = "";
        if (switchType == Const.NB_DOUBLE) {
            LampSwitchBean bean = codeList.get(0);
            if (bean.isCheck()) {
                type = "3";
            } else if (bean.isCheckMain() && !bean.isCheckAux()) {
                type = "1";
            } else if (!bean.isCheckMain() && bean.isCheckAux()) {
                type = "2";
            }
        }

        Map<String, Object> params = new HashMap<>();
        params.put("codeList", list);
        params.put("type", type); // 1：主灯 2：辅灯 3：主辅灯全选  ""：NB 单灯
        params.put("value", value); //1：100% 2：75% 3：50% 4：25% 0：0%
        mKalleCenter.postJson(Api.ADJUST_NB_BRIGHTNESSES, params, true, new KalleCallBack() {
            @Override
            public void onSuccess(String result, String msg) {
                mView.showMsg(msg);
                mView.onSuccess();
            }

            @Override
            public void onFailed(String msg) {
                if (null != mView)
                    mView.showMsg(msg);
            }
        });
    }

}
